Skip to content

VPC restart cleanup for Public networks with multi-CIDR data#12622

Open
jeanvetorello wants to merge 7 commits intoapache:4.22from
jeanvetorello:fix/vpc-restart-cidr-minimal
Open

VPC restart cleanup for Public networks with multi-CIDR data#12622
jeanvetorello wants to merge 7 commits intoapache:4.22from
jeanvetorello:fix/vpc-restart-cidr-minimal

Conversation

@jeanvetorello
Copy link
Copy Markdown
Contributor

@jeanvetorello jeanvetorello commented Feb 9, 2026

#12621
Fix VPC restart with multi-CIDR networks: handle comma-separated CIDR in NetworkVO.equals()

When a network has multiple CIDRs (e.g. '192.168.2.0/24,160.0.0.0/24'), NetworkVO.equals() passes the raw comma-separated string to NetUtils.isNetworkAWithinNetworkB() which expects a single CIDR, causing 'cidr is not formatted correctly' error during VPC restart with cleanup=true.

Extract only the first CIDR value before passing to NetUtils.

Description

This PR addresses VPC restart failures during cleanup in environments where Public networks contain legacy aggregated network data (multiple values stored in network-level CIDR and gateway fields).

This PR...

Types of changes

Bug fix (non-breaking change which fixes an issue)

Bug Severity

  • Major

Screenshots (if appropriate):

How Has This Been Tested?

  • Reproduced the issue on a CloudStack 4.21.0.0 environment with two public IP ranges
    on different VLANs assigned to the same VPC
  • Applied the fix and confirmed VPC restart with cleanup=true completes successfully
  • Verified unit tests pass for NetworkVO.equals() with both single and comma-separated CIDRs

How did you try to break this feature and the system with this change?

@sureshanaparti
Copy link
Copy Markdown
Contributor

@blueorangutan package

@sureshanaparti
Copy link
Copy Markdown
Contributor

@blueorangutan package

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 10, 2026

Codecov Report

❌ Patch coverage is 0% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 17.60%. Comparing base (59b6c32) to head (ca2c325).
⚠️ Report is 1 commits behind head on 4.22.

Files with missing lines Patch % Lines
.../cloud/configuration/ConfigurationManagerImpl.java 0.00% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               4.22   #12622   +/-   ##
=========================================
  Coverage     17.60%   17.60%           
- Complexity    15676    15677    +1     
=========================================
  Files          5918     5918           
  Lines        531667   531669    +2     
  Branches      65001    65002    +1     
=========================================
+ Hits          93617    93624    +7     
+ Misses       427491   427486    -5     
  Partials      10559    10559           
Flag Coverage Δ
uitests 3.70% <ø> (ø)
unittests 18.68% <0.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sureshanaparti
Copy link
Copy Markdown
Contributor

@blueorangutan package

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes VPC restart failures for multi-CIDR networks by ensuring NetworkVO.equals() does not pass a raw comma-separated CIDR list into NetUtils.isNetworkAWithinNetworkB(), which expects a single CIDR.

Changes:

  • Normalize cidr values in NetworkVO.equals() by extracting the first CIDR from comma-separated strings before comparing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@DaanHoogland
Copy link
Copy Markdown
Contributor

@blueorangutan package

@blueorangutan
Copy link
Copy Markdown

@DaanHoogland a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✖️ debian ✔️ suse15. SL-JID 16776

@weizhouapache
Copy link
Copy Markdown
Member

as we discussed in the comments of #12621, we need to work on another solution

can you work on the fix ? cc @jeanvetorello @sureshanaparti

@sureshanaparti
Copy link
Copy Markdown
Contributor

@jeanvetorello can you rebase this PR with 4.22 branch, and address the outstanding comments.

jean and others added 3 commits March 10, 2026 10:55
… in NetworkVO.equals()

When a network has multiple CIDRs (e.g. '192.168.2.0/24,160.0.0.0/24'),
NetworkVO.equals() passes the raw comma-separated string to
NetUtils.isNetworkAWithinNetworkB() which expects a single CIDR,
causing 'cidr is not formatted correctly' error during VPC restart
with cleanup=true.

Extract only the first CIDR value before passing to NetUtils.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…works

addCidrAndGatewayForIpv4/Ipv6 (introduced by PR apache#11249) was called for all
network types without checking if the network is Public. This caused
comma-separated CIDRs to be stored on Public networks, which then triggered
'cidr is not formatted correctly' errors during VPC restart.

Add TrafficType.Public guard in both the VLAN creation (addCidr) and
VLAN deletion (removeCidr) paths in ConfigurationManagerImpl.
@DaanHoogland
Copy link
Copy Markdown
Contributor

@blueorangutan package

@blueorangutan
Copy link
Copy Markdown

@DaanHoogland a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link
Copy Markdown

Packaging result [SF]: ✖️ el8 ✖️ el9 ✖️ debian ✖️ suse15. SL-JID 17078

jean added 2 commits March 19, 2026 13:04
@DaanHoogland
Copy link
Copy Markdown
Contributor

@blueorangutan package

@blueorangutan
Copy link
Copy Markdown

@DaanHoogland a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✖️ debian ✔️ suse15. SL-JID 17200

@DaanHoogland DaanHoogland changed the title Fix VPC restart with multi-CIDR networks: handle comma-separated CIDR… handle comma-separated CIDR in NetworkVO.equals() Mar 20, 2026
@blueorangutan
Copy link
Copy Markdown

Packaging result [SF]: ✖️ el8 ✖️ el9 ✔️ debian ✖️ suse15. SL-JID 17207

@weizhouapache
Copy link
Copy Markdown
Member

@jeanvetorello
thanks for the update

can you update the PR title add description ?

Can you also add a SQL change to update some fields of Public network to NULL ? https://github.com/apache/cloudstack/blob/4.22/engine/schema/src/main/resources/META-INF/db/schema-42200to42210.sql

I think

        broadcast_uri: NULL
              gateway: NULL
                 cidr: NULL
          ip6_gateway: NULL
             ip6_cidr: NULL

@jeanvetorello jeanvetorello changed the title handle comma-separated CIDR in NetworkVO.equals() VPC restart cleanup for Public networks with multi-CIDR data Mar 20, 2026
Copy link
Copy Markdown
Member

@weizhouapache weizhouapache left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code lgtm

@jeanvetorello
can you plaese update the description as well ? thanks

@github-actions
Copy link
Copy Markdown

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

@DaanHoogland
Copy link
Copy Markdown
Contributor

@weizhouapache, @jeanvetorello did update the title. Is this to satisfaction?]
@sureshanaparti, is this lgty now?

@DaanHoogland DaanHoogland requested a review from Copilot April 1, 2026 10:14
@DaanHoogland
Copy link
Copy Markdown
Contributor

@blueorangutan package

@blueorangutan
Copy link
Copy Markdown

@DaanHoogland a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

`cidr` = NULL,
`ip6_gateway` = NULL,
`ip6_cidr` = NULL
WHERE `traffic_type` = 'Public';
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This migration nulls cidr/gateway (and broadcast_uri) for all traffic_type='Public' networks. With the current NetworkVO.equals() implementation, two Public networks with cidr == null compare as equal, while NetworkVO.hashCode() is based on id; this violates the equals/hashCode contract and can break HashSet/Map behavior (and may become more likely after this UPDATE makes cidr null everywhere). Consider either (a) updating NetworkVO.equals()/hashCode() to be consistent (and to handle comma-separated CIDRs as described in the PR), or (b) narrowing this UPDATE to only sanitize rows that actually contain legacy comma-separated values so you don’t increase the number of cidr == null Public networks.

Suggested change
WHERE `traffic_type` = 'Public';
WHERE `traffic_type` = 'Public`
AND (
`cidr` LIKE '%,%'
OR `ip6_cidr` LIKE '%,%'
OR `gateway` LIKE '%,%'
OR `ip6_gateway` LIKE '%,%'
);

Copilot uses AI. Check for mistakes.
Comment on lines +6510 to +6514
final NetworkVO networkVO = _networkDao.findById(networkId);

if (ipv4) {
removeCidrAndGatewayForIpv4(networkId, deletedVlan);
} else if (ipv6) {
removeCidrAndGatewayForIpv6(networkId, deletedVlan);
if (networkVO != null && networkVO.getTrafficType() != TrafficType.Public) {
if (ipv4) {
removeCidrAndGatewayForIpv4(networkId, deletedVlan);
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

networkVO is fetched here to check traffic type, but removeCidrAndGatewayForIpv4/Ipv6 immediately re-fetch the same NetworkVO again. To avoid the extra DB hit (and keep the code easier to follow), consider passing the already-fetched NetworkVO into the remove* helpers or moving the traffic-type guard into those helpers.

Copilot uses AI. Check for mistakes.
@blueorangutan
Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 17325

@DaanHoogland
Copy link
Copy Markdown
Contributor

@blueorangutan test

@blueorangutan
Copy link
Copy Markdown

@DaanHoogland a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VPC restart with cleanup fails when VPC has multiple public IP ranges from different VLANs — "cidr is not formatted correctly"

6 participants